/**
 * @Author: LiMeng
 * @Date: 2017/4/15
 */
$(function () {
    $('#btn_save').on("click", function () {
        $.messager.progress();	// 显示进度条
        $('#form1').form('submit', {
            url: ROOT_PATH + '/contractor/contractorStaff/toggle.shtml',
            onSubmit: function (param) {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    $.messager.progress('close');	// 如果表单是无效的则隐藏进度条
                }
                return isValid;	// 返回false终止表单提交
            },
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success) {
                    $.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message, {time: 1000, icon: 1}, function () {
                        parent.$('#dg1').datagrid('load');
                        parent.layer.closeAll(); //先得到当前iframe层的索引
                    });
                } else {
                    $.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message, {time: 1000, icon: 2});
                }
            }
        });
    });
    $('#btn_clear').on("click", function () {
        $('#form1').form('reset');
    });
});